package logic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"zeroOne/user_srv/api/internal/svc"
	"zeroOne/user_srv/api/internal/types"
	"zeroOne/user_srv/user_rpc/userrpc"
)

type RegisterLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRegisterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RegisterLogic {
	return &RegisterLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RegisterLogic) Register(req *types.RegisterReq) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	register, err := l.svcCtx.UserRpc.UserRegister(l.ctx, &userrpc.UserRegRequest{
		Username: req.Username,
		Password: req.Password,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: "注册失败" + err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "注册成功",
		Data:    register,
		Code:    200,
	}, nil
}
